package pl.th.permission;

import android.Manifest;

/**
 * request the permission {@link android.Manifest.permission#ACCESS_BACKGROUND_LOCATION}
 */
public class BGLocationPerQProcessor extends AbstractProcessor{

    BGLocationPerQProcessor(String... permissions) {
        super(permissions);
    }

    @Override
    public void process(ProxyFragment proxy) {
        boolean fineLocEnabled = Utils.isPermissionsGranted(
                Manifest.permission.ACCESS_FINE_LOCATION, proxy.getActivity()
        );
        boolean coarseLocEnabled = Utils.isPermissionsGranted(
                Manifest.permission.ACCESS_COARSE_LOCATION, proxy.getActivity()
        );
        if (fineLocEnabled || coarseLocEnabled) {
            if (PermissionCompat.isAccessBGLocationGranted(proxy.getContext())) {
                proxy.workOnNextProcessor();
            } else {
                proxy.requestPermissions(realPermissions);
            }
        } else {
            proxy.workOnNextProcessor();
        }
    }
}
